package com.crazymaker.springcloud.standard.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.List;

@Data
@ConfigurationProperties(prefix = "application.rate.limit.redis" )
public class RedisRateLimitProperties
{
    private List<TypeInfo> typeInfos;

    String rateLimitLua = "classpath:script/rate_limiter.lua";


    @Data
    public static class TypeInfo
    {

        private String key;

        private String type = "default";

        private Integer maxPermits;

        private Integer rate;

        private static final String RATE_LIMITER_KEY_PREFIX = "rate_limiter:";


        public String fullKey()
        {
            return RATE_LIMITER_KEY_PREFIX + type + ":" + key;
        }

        public String cashKey()
        {
            return type + ":" + key;
        }
    }

}
